<template>
	<view class="content">
		<button class="size" @tap="isSupport">isSupport 当前设备环境是否支持指纹识别 {{hasSupport}}</button>
		<button class="size" @tap="isKeyguardSecure">当前设备是否设置密码锁屏 {{secure}}</button>
		<button class="size" @tap="isEnrolledFingerprints">当前设备是否已经录入指纹 {{prints}}</button>
		<button class="size" @tap="authenticate">指纹识别认证</button>
		<button class="size" @tap="cancel">取消指纹识别认证</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				hasSupport: "未知",
				secure: "未知",
				prints: '未知'
			}
		},
		onLoad() {

		},
		methods: {
			isSupport() {
				// 支持=>true, 不支持=>false
				const flag = plus.fingerprint.isSupport()
				this.hasSupport = flag ? "支持" : '不支持';
			},
			isKeyguardSecure() {
				// 支持=>true, 不支持=>false
				const flag = plus.fingerprint.isSupport()
				this.secure = flag ? "支持" : '不支持';
			},
			isEnrolledFingerprints() {
				// 支持=>true, 不支持=>false
				const flag = plus.fingerprint.isEnrolledFingerprints()
				this.prints = flag ? "支持" : '不支持';
			},
			authenticate() {
				var waiting = null;
				plus.fingerprint.authenticate(function() {
					plus.nativeUI.closeWaiting(); //兼容Android平台关闭等待框
					console.log('指纹识别成功');
				}, function(e) {
					switch (e.code) {
						case e.AUTHENTICATE_MISMATCH:
							plus.nativeUI.toast('指纹匹配失败，请重新输入');
							break;
						case e.AUTHENTICATE_OVERLIMIT:
							plus.nativeUI.closeWaiting(); //兼容Android平台关闭等待框
							plus.nativeUI.alert('指纹识别失败次数超出限制，请使用其它方式进行认证');
							break;
						default:
							plus.nativeUI.closeWaiting(); //兼容Android平台关闭等待框
							plus.nativeUI.alert('指纹识别失败(' + e.code + ')，请重试');
							break;
					}
				});
				// Android平台弹出等待提示框 
				if ('Android' == plus.os.name) {
					plus.nativeUI.showWaiting('指纹识别中...');
				}
			},
			cancel(){
				plus.fingerprint.cancel();
			}

		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.size {
		margin: 30rpx 0;
	}
</style>
